<?php

	$myusername=$_POST['usuario']; 
	$mypassword=$_POST['password'];
	
	$con = mysql_connect("mysql.codefactorycr.com","a80630","patito3");
	if (!$con)
	{
		die('Error al conectarse a la base de datos: ' . mysql_error());
	}
	
	mysql_select_db("a80630", $con);
	
	$sql="SELECT * FROM usuarios WHERE username='$myusername' and password='$mypassword'";
	
	$result = mysql_query($sql);

	$count = mysql_num_rows($result);
	
	if($count == 1){
		//session_register("myusername");
		session_start();
		$_SESSION['myusername'] = $myusername;
		header("location:main.php");
	}
	else {
		header("location:index.php?user=$myusername");
	}

	mysql_close($con);
?>
